//
//  ShopCollectCell.m
//  newProject
//
//  Created by 李航飞 on 2017/6/11.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "ShopCollectCell.h"

@implementation ShopCollectCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpView];
    }
    return self;
}


- (void)setUpView{
    
    UIImageView *leftImageView = [[UIImageView alloc] init];
//    leftImageView.backgroundColor = [UIColor redColor];
    self.leftImageView = leftImageView;
    [self addSubview:leftImageView];
    
    _jingXuanImg =[[UIImageView alloc] init];
    [self addSubview:_jingXuanImg];
    
    UILabel *titleLable = [[UILabel alloc] init];
    self.titleLable = titleLable;
    titleLable.font = [UIFont systemFontOfSize:14*kScrenWidth];
    [self addSubview:titleLable];
    titleLable.textAlignment = NSTextAlignmentLeft;
    
    UILabel *detailLable = [[UILabel alloc] init];
    self.detailLable = detailLable;
    self.detailLable.textAlignment = NSTextAlignmentLeft;
    self.detailLable.font = [UIFont systemFontOfSize:14*kScrenWidth];
    self.detailLable.textColor=ORANGE_COLOR;
    [self addSubview:detailLable];
    
    _oldPriceLabel = [[UILabel alloc]init];
    _oldPriceLabel.font = FONT(8);
    _oldPriceLabel.textColor = RGB0X(0x9C9C9C);
    [self addSubview:_oldPriceLabel];
    
    UIButton *reduceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    reduceBtn.frame = CGRectMake( 265*kScrenWidth, 48*kScrenHidth, 25*kScrenWidth, 25*kScrenWidth);
    [reduceBtn addTarget:self action:@selector(changeNum:) forControlEvents:UIControlEventTouchUpInside];
    reduceBtn.tag = 100;
    [reduceBtn setImage:[UIImage imageNamed:@"goujianx2"] forState:UIControlStateNormal];
//    reduceBtn.backgroundColor = [UIColor cyanColor];
    [self addSubview:reduceBtn];
    
    UILabel *numLable = [[UILabel alloc] init];
    self.numLable = numLable;
//    numLable.backgroundColor = [UIColor grayColor];
    [self addSubview:numLable];
    _numLable.textAlignment = UITextAlignmentCenter;
    
    UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    addBtn.frame = CGRectMake( 322*kScrenWidth, 48*kScrenHidth, 25*kScrenWidth, 25*kScrenWidth);
    //addBtn setImage: forState:
    addBtn.tag = 200;
    [addBtn setImage:[UIImage imageNamed:@"goujiax2"] forState:UIControlStateNormal];
//    addBtn.backgroundColor = [UIColor redColor];
    [self addSubview:addBtn];
    [addBtn addTarget:self action:@selector(changeNum:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)changeNum:(UIButton *)btn{
    self.block(btn);
    
    if (btn.tag == 100) {
        if (self.indexNum>0) {
            self.indexNum--;
        }
        
    }else{
        self.indexNum++;
    }

    self.numLable.text = [NSString stringWithFormat:@"%ld",self.indexNum];

}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    _leftImageView.frame = CGRectMake(15*kScrenWidth, 20*kScrenHidth, 75*kScrenWidth, 75*kScrenWidth);
    
    _titleLable.frame = CGRectMake(135*kScrenWidth, 15*kScrenHidth, 200*kScrenWidth, 20*kScrenHidth);
    
    _detailLable.frame = CGRectMake(100*kScrenWidth, 60*kScrenHidth, 280*kScrenWidth, 18*kScrenHidth);
    _oldPriceLabel.frame = CGRectMake(145/WIDTH_6_SCALE, 66/WIDTH_6_SCALE, 280/WIDTH_6_SCALE, 8/WIDTH_6_SCALE);
    self.numLable.frame = CGRectMake(291*kScrenWidth, 52*kScrenHidth, 30*kScrenWidth, 15*kScrenHidth);
    
    _jingXuanImg.frame=CGRectMake(100*kScrenWidth, 18*kScrenHidth, 30*kScrenWidth, 15*kScrenHidth);
    
    self.numLable.text = [NSString stringWithFormat:@"%ld",self.indexNum];
}













@end
